package com.hotel.dao.impl;

import com.hotel.dao.LodgingInfoDao;
import com.hotel.entity.LodgingInfo;
import com.hotel.utils.JdbcUtils;

import java.sql.SQLException;

/**
 * @Author Str
 * @Date 2021/11/4 9:55
 * @Description :
 */
public class LodgingInfoDaoImpl implements LodgingInfoDao {
    @Override
    public int addLodgingInfo(LodgingInfo lodgingInfo) throws SQLException {
        String fields = "id" +
                ",entryDate" +
                ",leaveDate" +
                ",days" +
                ",roomId" +
                ",deposit" +
                ",reservationId" +
                ",operatorId" +
                ",registerId" +
                ",registerName" +
                ",createDate";
        String sql = "insert into lodginginfo(" + fields + ") " + " value(?,?,?,?,?,?,?,?,?,?,now())";
        int updateCnt = JdbcUtils.update(sql, lodgingInfo.getId(),
                lodgingInfo.getEntryDate(), lodgingInfo.getLeaveDate(),
                lodgingInfo.getDays(), lodgingInfo.getRoomId(),
                lodgingInfo.getDeposit(), null,
                lodgingInfo.getOperatorId(), lodgingInfo.getRegisterId(),
                lodgingInfo.getRegisterName());
        return updateCnt;
    }

    @Override
    public int updateLodgingInfo(LodgingInfo lodgingInfo) throws SQLException {
        String sqlUpdate = "update lodginginfo set entryDate=?,leaveDate=?,days=?,roomId=?," +
                " deposit=?,operatorId=?,registerId=? registerName=? where id=?;";
        return JdbcUtils.update(sqlUpdate, lodgingInfo.getEntryDate(),
                lodgingInfo.getLeaveDate(), lodgingInfo.getDays(),
                lodgingInfo.getRoomId(), lodgingInfo.getDeposit(),
                lodgingInfo.getOperatorId(), lodgingInfo.getRegisterId(),
                lodgingInfo.getRegisterName(),lodgingInfo.getId());
    }
}
